﻿

namespace Mulala.Cavan.TestAppService.InformationModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Spring.Context;
    using Mulala.Cavan.Application.MainBoundedContext.InformationModule;
    using NUnit.Framework;
    using Spring.Context.Support;
    using Mulala.Cavan.Domain.MainBoundedContext.InformationModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SecurityModule;
    using Mulala.Cavan.Domain.Seedwork;
    using Mulala.Cavan.Application.MainBoundedContext.MulalaModule;

    public class TestUserMessageAppService
    {
        private IApplicationContext context;
        private IUserMessageAppService UserMessageAppService { get; set; }

        [SetUp]
        public void SetUp()
        {
            context = ContextRegistry.GetContext();
            this.UserMessageAppService = this.context.GetObject(MulalaAppServiceConst.USERMESSAGEAPPSERVICE) as IUserMessageAppService;
        }

        [Test]
        public void TestAddMessage()
        {
            UserAccount ownerUser = UserAccountFactory.CreateUserAccount("");
            ownerUser.ID = 27;
            UserAccount messagerUser = UserAccountFactory.CreateUserAccount("proprietor1");
            messagerUser.ID = 24;
            messagerUser.Roles = new List<Role>();
            messagerUser.Roles.Add(RoleFactory.CreateRole(SecurityIdentifier.Role.Proprietor.GetHashCode()));
            UserMessage userMessage = UserMessageFactory.CreateUserMessage(ownerUser, "test", 0, 0, messagerUser, false, DateTime.Now, messagerUser.Name);

            BoolGenericResult<UserMessage> result = this.UserMessageAppService.Add(userMessage);

            Assert.AreEqual(true, result.IsSuccess);
        }

        [Test]
        public void TestAddMessageReply()
        {
            UserAccount ownerUser = UserAccountFactory.CreateUserAccount("");
            ownerUser.ID = 27;
            UserAccount messagerUser = UserAccountFactory.CreateUserAccount("corporation1");
            messagerUser.ID = 27;
            messagerUser.Roles = new List<Role>();
            messagerUser.Roles.Add(RoleFactory.CreateRole(SecurityIdentifier.Role.Corporation.GetHashCode()));
            UserMessage userMessage = UserMessageFactory.CreateUserMessage(ownerUser, "test_reply", 1, 0, messagerUser, false, DateTime.Now, messagerUser.Name);

            BoolGenericResult<UserMessage> result = this.UserMessageAppService.AddUserMessageReply(userMessage);

            Assert.AreEqual(true, result.IsSuccess);
        }
    }
}
